package Form

import (
	log2 "clientDemo/service/log"
	login_mod "clientDemo/service/login-mod"
	"clientDemo/service/modulemgr"
	"clientDemo/ui/walk_ui/widget"
	"fmt"
	"github.com/lxn/walk"
	"log"
)

var Name = "form_test"

type FormModule struct {
	logger      *log.Logger
	loginModule login_mod.ILoginModule
	mainWindow  *walk.MainWindow
	model       *widget.TableModel
	tableView   *walk.TableView
	trayIcon    *walk.NotifyIcon
}

func NewMainFormModule() *FormModule {
	return &FormModule{}
}
func (m *FormModule) Init(mm modulemgr.IModuleManager) (bool, error) {
	m.logger = log2.Logger
	var ok bool
	m.loginModule, ok = mm.GetModule(login_mod.Name).(login_mod.ILoginModule)
	if !ok {
		return false, fmt.Errorf("failed to assert module to IConfigModule")
	}
	return true, nil
}
func (m *FormModule) Run(mm modulemgr.IModuleManager) (bool, error) {
	isLogin := m.loginModule.CheckLoginStatus()
	m.CreateMainForm(m.mainWindow, isLogin)
	return true, nil
}
func (m *FormModule) CreateMainForm(mw *walk.MainWindow, isLogin bool) {
	if !isLogin {
		m.LoginMainForm()
	} else {
		m.DemoSelectForm()
	}
}
